package org.bt4girls.common.model.result;

import lombok.Data;

@Data
public class ResultDTO {
    private int code;
    private String msg;
    private Object data;


    private ResultDTO(ErrorCode arg) {
        init(arg, null);
    }

    private ResultDTO(ErrorCode arg, Object data) {
        init(arg, data);
    }

    public static ResultDTO success(Object data) {
        return new ResultDTO(ErrorCode.REQUEST_SUCCESS, data);
    }

    public static ResultDTO page(ResultPageDTO page) {
        return new ResultDTO(ErrorCode.REQUEST_SUCCESS, page);
    }

    public static ResultDTO fail(ErrorCode arg) {
        return new ResultDTO(arg, null);
    }

    public static ResultDTO fail(ErrorCode arg, Object data) {
        return new ResultDTO(arg, data);
    }

    public void init(ErrorCode arg, Object data) {
        this.code = arg.getCode();
        this.msg = arg.getMsg();
        this.data = data;
    }

}
